package com.stylefeng.guns.biz.banner.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.banner.model.TBanner;
import com.stylefeng.guns.biz.banner.service.ITBannerService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 轮播图控制器
 *
 * @author fengshuonan
 * @Date 2018-06-14 06:15:58
 */
@Controller
@RequestMapping("/tBanner")
public class TBannerController extends BaseController {

    private String PREFIX = "/app/tBanner/";

    @Autowired
    private ITBannerService tBannerService;

    /**
     * 跳转到轮播图首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tBanner.html";
    }

    /**
     * 跳转到添加轮播图
     */
    @RequestMapping("/tBanner_add")
    public String tBannerAdd() {
        return PREFIX + "tBanner_add.html";
    }

    /**
     * 跳转到修改轮播图
     */
    @RequestMapping("/tBanner_update/{tBannerId}")
    public String tBannerUpdate(@PathVariable Integer tBannerId, Model model) {
        TBanner tBanner = tBannerService.selectById(tBannerId);
        model.addAttribute("item",tBanner);
        LogObjectHolder.me().set(tBanner);
        return PREFIX + "tBanner_edit.html";
    }

    /**
     * 获取轮播图列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid,String type) {
    	EntityWrapper<TBanner> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id_key", appid);
    	wrapper.eq("type", type);
        return tBannerService.selectList(wrapper);
    }

    /**
     * 新增轮播图
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TBanner tBanner) {
        tBannerService.insert(tBanner);
        return SUCCESS_TIP;
    }

    /**
     * 删除轮播图
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long tBannerId) {
        tBannerService.deleteById(tBannerId);
        return SUCCESS_TIP;
    }

    /**
     * 修改轮播图
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TBanner tBanner) {
        tBannerService.updateById(tBanner);
        return SUCCESS_TIP;
    }

    /**
     * 轮播图详情
     */
    @RequestMapping(value = "/detail/{tBannerId}")
    @ResponseBody
    public Object detail(@PathVariable("tBannerId") Long tBannerId) {
        return tBannerService.selectById(tBannerId);
    }
}
